package com.developer.platform.infrastructure.security;

import com.developer.platform.domain.security.AuthenticationInfo;
import com.developer.platform.domain.service.IAuthorizingRealm;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

/**
 * @author ：qiaoliang
 * @date ：2020-11-06
 */
public class SecurityAuthenticationProvider implements org.springframework.security.authentication.AuthenticationProvider {

    private final IAuthorizingRealm authorizingRealm;

    public SecurityAuthenticationProvider(IAuthorizingRealm authorizingRealm) {
        this.authorizingRealm = authorizingRealm;
    }

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        AuthenticationInfo customAuthenticationToken = (AuthenticationInfo)authentication;
        return authorizingRealm.doGetAuthenticationInfo(customAuthenticationToken);
    }

    @Override
    public boolean supports(Class<?> aClass) {
        return true;
    }


}
